﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SuperSocket.SocketBase.Command;
using SuperSocketServer.AppBase;

namespace SuperSocketServer.Commands
{
  public  class Login : CommandBase<MySession, MyRequestInfo>
    {
        private int Action =110;
        public override string Name
        {
            get { return Action.ToString(); }
        }

        /// <summary>
        /// 上行（来自客户端的信息）
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestInfo"></param>
        public override void ExecuteCommand(MySession session, MyRequestInfo requestInfo)
        {
            //添加判断登陆是否可以成功的逻辑
            var body = requestInfo.Body;
            session.OrgCode = body;
            Console.WriteLine("登陆命令被执行");
            Console.WriteLine("用户是："+requestInfo.Body);
            Console.WriteLine("用户ID是："+session.SessionID);
            Push(session,1);
        }

        /// <summary>
        ///  下行(推送)
        /// </summary>
        public void Push(MySession session, byte status)
        {
            var response = new byte[] { 0, 1, 0, 2, 79, 75 }; //OK
            session.Send(response, 0, response.Length);
        }
    }
}
